package com.wdc.deliveryrobot.dialog;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.app.SearchManager;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdc.deliveryrobot.R;

public class HintDialog {

    private Dialog dialog;
    private TextView messageTextView;
    private Button okButton;
    private Button cancelButton;

    private LinearLayout imageButton;


    public HintDialog(Context context) {
        dialog = new Dialog(context);
        dialog.setContentView(R.layout.dialog_hint); // 确保这个文件名与XML文件一致
        dialog.setCancelable(false); // 设置为不可取消，除非明确调用取消

        messageTextView = dialog.findViewById(R.id.message);
        okButton = dialog.findViewById(R.id.ok_button);
        cancelButton = dialog.findViewById(R.id.cancel_button);
        imageButton = dialog.findViewById(R.id.close_button);

        // 设置 Dialog 的宽度和高度
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.copyFrom(dialog.getWindow().getAttributes());
        layoutParams.width = 350; // 或设置为具体的像素值
        layoutParams.height = 250; // 或设置为具体的像素值
        // 设置 Dialog 的背景为圆角
        dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_background);
        dialog.getWindow().setAttributes(layoutParams);



        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               dismiss();

            }
        });
    }

    public void setMessage(String message) {
        messageTextView.setText(message);
    }

    public void setOkButtonClickListener(final View.OnClickListener listener) {
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dismiss();

            }
        });
    }

    public void setCancelButtonClickListener(final View.OnClickListener listener) {
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dismiss();

            }
        });
    }

    public void show() {
        View decorView = dialog.getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        decorView.setSystemUiVisibility(uiOptions);

        // 使 ActionBar 隐藏
//        if (dialog.getSupportActionBar() != null) {
//            dialog.getSupportActionBar().hide();
//        }
        dialog.show();

    }

    public void dismiss() {
        dialog.dismiss();

    }

    public boolean isShowing(){
        return dialog.isShowing();
    }

}